﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ObjectTransposeApi.Helper
{
    /// <summary/>
    internal static class NullableHelper
    {
        /// <summary/>
        internal static Type FetchNullableType(Type type)
        {
            // is the instance generic
            if (!type.IsGenericType)
            {
                return null;
            }

            // is this instance generic type a match
            if (type.GetGenericTypeDefinition() != typeof(Nullable<>))
            {
                return null;
            }

            // get the list of generic parameter types
            Type[] destinationGenericParameterTypes = type.GetGenericArguments();
     
            // return the first
            return destinationGenericParameterTypes[0];
        }
    }
}
